package setting

import (
	"github.com/go-ini/ini"

	"log"
	"time"
)
var (
	Cfg     *ini.File
	RunMode string
	HTTPPort int
	ReadTimeOut time.Duration
	WriteTimeOut time.Duration
	PageSize int
)

func loadBase(){
	RunMode = Cfg.Section("").Key("RUN_MODE").MustString("debug")
}

func loadServer(){
	sec,err := Cfg.GetSection("server")
	if err !=nil {
		log.Fatalf("fail tog section 'server' ")
	}
	HTTPPort =sec.Key("HTTP_PORT").MustInt(7000)
	ReadTimeOut =time.Duration(sec.Key("READ_TIMEOUT").MustInt(60))
	WriteTimeOut =time.Duration(sec.Key("WRITE_TIMEOUT").MustInt(60))
}

func loadApp(){
	sec,err := Cfg.GetSection("app")
	if err !=nil{
		log.Fatalf("fail tog get section 'app' ")
	}
    PageSize =sec.Key("PAGE_SIZE").MustInt(10)

}

func init(){
	var err error
	Cfg,err =ini.Load("conf/gcconf.ini")
	if err !=nil{
		log.Fatalf("fail to parse conf/gcconf.ini ")
	}
	loadBase()
	loadServer()
	loadApp()
}